<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Base_Controller extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('panel/loginModel');
    }

    public function index()
    {
        echo "fsdf";
        exit;

        if($this->session->userdata('UserID')){
            $this->load->view('panel/dashboard');
        }else{
            $this->load->view('panel/index');
        }
    }

    public function dashboard(){
        if($this->session->userdata('UserID')){
            $this->load->view('panel/dashboard');
        }else{
            redirect('admin_panel/base/sign_in');
        }
    }

    public function sign_in() 
    {
        if($this->session->userdata('UserID')){
            redirect('admin_panel/base/dashboard');
        }else{
            $this->load->view('panel/index');
        }
    }

    public function perform_signin()
    {
        if($this->input->post())
        {
            $user_exists = $this->loginModel->check_credentials($this->input->post('username'), $this->input->post('password'));

            if($user_exists == false)
            {
                $this->session->set_flashdata('error', 'Invalid username and password');
                redirect('admin_panel/index/sign_in');
            }

            $this->session->set_userdata('UserID',  $this->loginModel->id);
            $this->session->set_userdata('RoleName', $this->loginModel->role);
            $this->session->set_userdata('RoleID', $this->loginModel->role_id);
            $this->session->set_userdata('FirstName', $this->loginModel->firstname);
            $this->session->set_userdata('LastName', $this->loginModel->lastname);

            redirect('admin_panel/base/dashboard');
        }
    }

    #logout
    function logout () {
        $this->session->unset_userdata ('UserID');
        $this->session->unset_userdata ('RoleName');
        $this->session->unset_userdata ('RoleID');
        $this->session->unset_userdata ('FirstName');
        $this->session->unset_userdata ('LastName');

        redirect('admin_panel/base/sign_in');
    }

}

/* End of file main_category_controller.php */
/* Location: ./application/controllers/panel/main_category_controller.php */